package com.prs.crm.service.hr.impl;

import java.io.File;
import java.util.Collection;
import java.util.List;

import com.prs.crm.context.Attach;
import com.prs.crm.context.Constrains;
import com.prs.crm.context.FileUtil;
import com.prs.crm.context.ToolKits;
import com.prs.crm.dao.hr.ResumeDao;
import com.prs.crm.domain.hr.Resume;
import com.prs.crm.service.hr.ResumeService;
import com.prs.crm.service.impl.BaseServiceImpl;

public class ResumeServiceImpl extends BaseServiceImpl<Resume, ResumeDao>
		implements ResumeService {

	@Override
	public void saveResume(Resume resume, File photoImg,
			String photoImgFileName, File resumeAttach,
			String resumeAttachFileName) {
		// TODO Auto-generated method stub
		Attach pAttach = FileUtil.getInstance().saveFile(photoImg,
				photoImgFileName, "", Constrains.UPLOAD_DIR_RESUME);
		Attach rAttach = FileUtil.getInstance().saveFile(resumeAttach,
				resumeAttachFileName, "", Constrains.UPLOAD_DIR_RESUME);
		if (pAttach.getSrc() != null) {
			resume.setPhotoImg(pAttach.getSrc());
		}
		if (rAttach.getSrc() != null) {
			resume.setResumeFile(rAttach.getSrc());
		}

		this.getDao().save(resume);
	}

	@Override
	public Collection<Resume> getAllResume() {
		// TODO Auto-generated method stub
		return this.getDao().getAllResume();
	}

	@Override
	public Collection<Resume> getResumeByIds(Integer[] ids) {
		// TODO Auto-generated method stub
		return this.getDao().getResumeByIds(ToolKits.convertToIntAry(ids));
	}

	@Override
	public void submitAlterPerson(Resume resume, File file, String fileName) {
		// TODO Auto-generated method stub
		Attach pAttach = FileUtil.getInstance().saveFile(file,
				fileName, "", Constrains.UPLOAD_DIR_RESUME);
		if (pAttach.getSrc() != null) {
			resume.setPhotoImg(pAttach.getSrc());
		}
		this.getDao().save(resume);
	}

	@Override
	public Resume getResumeByid(String name) {
		// TODO Auto-generated method stub
		return this.getDao().getResumeByid(name);
	}
}
